// 引入基本模板
// 引入axios组件
import axios from 'axios';
import qs from 'qs'; // 处理数据  qs.stringify(params)
import { checkRule } from '@/assets/js/public';

const echarts = require('echarts/lib/echarts');
// 引入柱状图组件
require('echarts/lib/chart/line');
// 引入提示框和title组件
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');
// 引入公共js文件
export default {
  data() {
    return {};
  },
  computed: {
    title() {
      return this.$store.state.index.indexinfo;
    },
  },
  mounted() {
    const self = this;
    axios({
      method: 'post',
      url: '/admin/index/getEcharts',
      data: {},
    })
      .then((response) => {
        checkRule(response, self); // 检查是否有权限
        self.drawLine(response.data.date, response.data.number);
      })
      .catch((response) => {
        console.log(response);
      });
  },
  methods: {
    drawLine(date, number) {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(document.getElementById('myChart'));
      // 绘制图表
      myChart.setOption({
        title: { text: '近七天注册人数统计' },
        tooltip: {},
        xAxis: {
          data: date,
        },
        yAxis: {},
        series: [
          {
            name: '注册人数',
            type: 'line',
            data: number,
          },
        ],
      });
    },
  },
};
